package com.invengo.module_check.ui.fragment.opeartion.item;

import android.annotation.SuppressLint;
import android.text.TextUtils;

import androidx.annotation.NonNull;

import com.invengo.library_db.entity.module_check.ShelfBean;
import com.invengo.module_check.ui.fragment.opeartion.OpeartionInfoViewModel;

import java8.util.Optional;

import me.goldze.mvvmhabit.base.ItemViewModel;
import me.goldze.mvvmhabit.bus.event.SingleLiveEvent;

public class OpFirstPosItemViewModel extends ItemViewModel<OpeartionInfoViewModel> {

    public SingleLiveEvent<String> shelfName = new SingleLiveEvent<>();
    public SingleLiveEvent<String> firstBookName = new SingleLiveEvent<>();
    public SingleLiveEvent<String> firstBookID = new SingleLiveEvent<>();
    public SingleLiveEvent<String> firstBookCallNo = new SingleLiveEvent<>();

    public OpFirstPosItemViewModel(@NonNull OpeartionInfoViewModel viewModel, ShelfBean bean) {
        super(viewModel);
        shelfName.postValue(bean.getShelfName());
        Optional<String> firstBookName1 = Optional.ofNullable(bean.getFirstBookName());
        if (firstBookName1.isPresent()&& !TextUtils.isEmpty(firstBookName1.get())) {
            firstBookName.postValue("《"+firstBookName1.get()+"》");
        }else{
            firstBookName.postValue("");
        }
        firstBookID.postValue(Optional.ofNullable(bean.getFirstBookID()).orElse(""));
        firstBookCallNo.postValue(Optional.ofNullable(bean.getBookIndex()).orElse(""));
    }

    public int getPosition() {
        return viewModel.getPosition(this) + 1;
    }
}
